# _*_ coding: UTF-8 _*_
# @Time     : 2022/4/22 9:53
# @Author   : Li Jie
# @Site     : http://www.cdtest.cn/
# @File     : 下拉菜单操作.py
# @Software : PyCharm

from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select


def foo1():
    driver = webdriver.Chrome()

    driver.maximize_window()

    driver.get(r"D:\pyworkspace\t79\selenium3\example.html")

    time.sleep(1)

    # 找到下来菜单元素<select>
    el = driver.find_element(By.ID, 'Selector')
    # 构造下拉菜单类的对象
    select = Select(el)

    # 根据option的value属性选择
    select.select_by_value('peach')
    time.sleep(1)

    # 根据option的text选择
    select.select_by_visible_text('3.香蕉')
    time.sleep(1)

    # 根据option的索引值选择:从0开始
    select.select_by_index(4)
    time.sleep(1)

    driver.quit()


if __name__ == "__main__":
    foo1()
